﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using Indstillinger;

namespace Model
{
    [Serializable]
    public class Forbrug
    {
        //Attribut
        private DateTime dato;

        //Konstruktør
        public Forbrug(string produktNr)
        {
            this.dato = DateTime.Now;

            SqlConnection con = new SqlConnection(DbIndstillinger.HentConnectionString());
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;
            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            con.Open();

            cmd.CommandText = "opretForbrug";
            cmd.Parameters.Clear();
            cmd.Parameters.Add("@produktNr", System.Data.SqlDbType.NVarChar).Value = produktNr;
            cmd.Parameters.Add("@dato", System.Data.SqlDbType.DateTime, 50).Value = this.dato;
            cmd.ExecuteNonQuery();

            con.Close();
        }

        //Property
        public DateTime Dato
        {
            get { return dato; }  
        }


    }
}
